package com.xh.fma.commodity.controller;

import com.xh.fma.commodity.entity.CategoryEntity;
import com.xh.fma.commodity.service.CategoryService;
import com.xh.fma.commodity.vo.Catalog2Vo;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author 史建飞
 * @version 1.0
 */
@Controller
public class IndexController {

    @Resource
    private CategoryService categoryService;

    @GetMapping(value = {"/", "index.html"})
    private String indexPage(Model model) {

        List<CategoryEntity> categoryEntities = categoryService.listLeve1();
        model.addAttribute("categories", categoryEntities);
        return "index";
    }

    @GetMapping(value = {"/index/catalog.json"})
    @ResponseBody
    private Map<String, List<Catalog2Vo>> getCatalogJson() {

        Map<String, List<Catalog2Vo>> catalogJson = categoryService.getCatalogJson();

        System.out.println("+++++++++++++++++++++++++++");
        System.out.println(catalogJson.toString());
        System.out.println("+++++++++++++++++++++++++++");

        return catalogJson;
    }


}


